/**
 * Custom tile-layers for Google Maps.
 * The Google Maps v3 Javascript library must be loaded before this library.
 *
 * @version 2-0-0 (2011-05-01) http://code.google.com/p/gmaps-tilelayers/
 * @author DL
 */

///////////////////////////////////////////////////////////////////////////////

/**
 * Implements the google.maps.TileLayer interface for maps.google.com.
 * @see google.maps.TileLayer
 */
function GMapsMapTypeFactory() {
}

GMapsMapTypeFactory.createMapType = function (language) {
  var domain = ("https:" == document.location.protocol ? "https://mts.google.com" : "http://mt.google.com");
  var getTileUrl = function (coord, zoom) {
    var numTiles = (1 << zoom);
    if ((coord.x < 0) || (coord.x >= numTiles) || (coord.y < 0) || (coord.y >= numTiles)) {
      return null;
    }

    return domain + "/vt/lyrs=m" +
      "&hl=" + language +
      "&x=" + coord.x +
      "&y=" + coord.y +
      "&z=" + zoom;
  };

  var imageMapTypeOptions = {
    "name": "Map",
    "alt": "Show street map",
    "tileSize": new google.maps.Size(256, 256),
    "maxZoom": 22,
    "minZoom": 0,
    "getTileUrl": getTileUrl,
    "isPng": true,
    "opacity": 1.0
  };

  return new google.maps.ImageMapType(imageMapTypeOptions);
}
